package com.github.postsanf.yinian.view;

import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.github.postsanf.yinian.R;

public class StyleDialog extends Dialog implements View.OnClickListener {

    private ImageView iv_share_apart;
    private ImageView check_mark_apart;
    private ImageView iv_share_all;
    private ImageView check_mark_all;
    private RelativeLayout rl_btn_share;
    private int isApart = 0; // 1 分享部分 2 分享全部 3 分享链接
    private ImageView btn_iv_share_apart;
    private ImageView btn_iv_share_all;
    private Context context;
    private ImageView iv_share_link;
    private ImageView check_mark_link;
    private ImageView btn_iv_share_link;

    public StyleDialog(Context context) {
        super(context, R.style.style_dialog_style);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.style_dialog);
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.gravity = Gravity.BOTTOM;
        attributes.height = WindowManager.LayoutParams.WRAP_CONTENT;
        attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
        initView();
    }

    private void initView() {
        iv_share_apart = ((ImageView) findViewById(R.id.iv_share_apart));
        check_mark_apart = ((ImageView) findViewById(R.id.check_mark_apart));
        iv_share_all = (ImageView) findViewById(R.id.iv_share_all);
        check_mark_all = (ImageView) findViewById(R.id.check_mark_all);
        rl_btn_share = ((RelativeLayout) findViewById(R.id.rl_btn_share));
        btn_iv_share_apart = ((ImageView) findViewById(R.id.btn_iv_share_apart));
        btn_iv_share_all = (ImageView) findViewById(R.id.btn_iv_share_all);
        iv_share_link = ((ImageView) findViewById(R.id.iv_share_link));
        check_mark_link = ((ImageView) findViewById(R.id.check_mark_link));
        btn_iv_share_link = ((ImageView) findViewById(R.id.btn_iv_share_link));

        iv_share_link.setOnClickListener(this);
        check_mark_link.setOnClickListener(this);
        iv_share_apart.setOnClickListener(this);
        check_mark_apart.setOnClickListener(this);
        iv_share_all.setOnClickListener(this);
        check_mark_all.setOnClickListener(this);
        rl_btn_share.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_share_apart:
                isApart = 1;
                Log.d("yuhao", "iv_share_apart" + isApart);
                btn_iv_share_apart.setVisibility(View.VISIBLE);
                btn_iv_share_all.setVisibility(View.GONE);
                btn_iv_share_link.setVisibility(View.GONE);
                check_mark_apart.setImageResource(R.drawable.pitch_up);
                check_mark_all.setImageResource(R.drawable.no_pitch_up);
                check_mark_link.setImageResource(R.drawable.no_pitch_up);
                break;

            case R.id.iv_share_link:
                isApart = 3;
                btn_iv_share_apart.setVisibility(View.GONE);
                btn_iv_share_all.setVisibility(View.GONE);
                btn_iv_share_link.setVisibility(View.VISIBLE);
                check_mark_apart.setImageResource(R.drawable.no_pitch_up);
                check_mark_all.setImageResource(R.drawable.no_pitch_up);
                check_mark_link.setImageResource(R.drawable.pitch_up);
                break;

            case R.id.iv_share_all:
                isApart = 2;
                Log.d("yuhao", "iv_share_all" + isApart);
                btn_iv_share_apart.setVisibility(View.GONE);
                btn_iv_share_all.setVisibility(View.VISIBLE);
                btn_iv_share_link.setVisibility(View.GONE);
                check_mark_apart.setImageResource(R.drawable.no_pitch_up);
                check_mark_all.setImageResource(R.drawable.pitch_up);
                check_mark_link.setImageResource(R.drawable.no_pitch_up);
                break;


            case R.id.rl_btn_share:
                Log.d("yuhao", "Dialog_isApart" + isApart);
                SharedPreferences sp = context.getSharedPreferences("isApart", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                editor.putInt("isApart", isApart);
                editor.commit();
                isApart = 0;
                dismiss();
                break;

        }
    }
}
